class YoutubesController < ApplicationController
  # GET /youtubes
  # GET /youtubes.xml
  def index
    @youtubes = Youtube.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @youtubes }
    end
  end

  # GET /youtubes/1
  # GET /youtubes/1.xml
  def show
    @youtube = Youtube.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @youtube }
    end
  end

  # GET /youtubes/new
  # GET /youtubes/new.xml
  def new
    @youtube = Youtube.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @youtube }
    end
  end

  # GET /youtubes/1/edit
  def edit
    @youtube = Youtube.find(params[:id])
  end

  # POST /youtubes
  # POST /youtubes.xml
  def create
    @youtube = Youtube.new(params[:youtube])
    
    published = Time.parse(@youtube.published.to_s)
    unix_published = published.to_i
    
    updated = Time.parse(@youtube.updated.to_s)
    unix_updated = updated.to_i
    
    @youtube.update_attributes(:published => unix_published,
                              :updated => unix_updated)

    respond_to do |format|
      if @youtube.save
        flash[:notice] = 'Youtube was successfully created.'
        format.html { redirect_to(@youtube) }
        format.xml  { render :xml => @youtube, :status => :created, :location => @youtube }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @youtube.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /youtubes/1
  # PUT /youtubes/1.xml
  def update
    @youtube = Youtube.find(params[:id])

    respond_to do |format|
      if @youtube.update_attributes(params[:youtube])
        flash[:notice] = 'Youtube was successfully updated.'
        format.html { redirect_to(@youtube) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @youtube.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /youtubes/1
  # DELETE /youtubes/1.xml
  def destroy
    @youtube = Youtube.find(params[:id])
    @youtube.destroy

    respond_to do |format|
      format.html { redirect_to(youtubes_url) }
      format.xml  { head :ok }
    end
  end
end
